from curl_cffi import requests
import execjs

headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json',
    'Origin': 'https://pv4y-pc.youzy.cn',
    'Referer': 'https://pv4y-pc.youzy.cn/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'U-Sign': 'f6a8052b16fbe01064e4c4e86441a642',
    'u-token': '',
}

result = []

# 总共range(1,150)
for i in range(1, 10):
    json_data = {
        'keyword': '',
        'provinceNames': [],
        'natureTypes': [],
        'eduLevel': '',
        'categories': [],
        'features': [],
        'pageIndex': i,
        'pageSize': 20,
        'sort': 11,
    }

    js_code = open('code.js', 'r', encoding='utf-8').read()
    ctx = execjs.compile(js_code)
    url = '/youzy.dms.basiclib.api.college.query'
    u_sign = ctx.call('get_u_sign', url, json_data)
    headers['U-Sign'] = u_sign

    response = requests.post(
        'https://uwf7de983aad7a717eb.youzy.cn/youzy.dms.basiclib.api.college.query',
        headers=headers,
        json=json_data,
        impersonate = 'chrome110'
    )

    rst = response.json()['result']['items']
    for colleage in rst:
        result.append((colleage['cityName'], colleage['cnName'], colleage['code'], colleage['features'], colleage['provinceName']))

print(result)
with open('colleage.text', 'w') as f:
    f.write(str(result))


